let express = require('express');
let https = require('https');
let request = require('request');
var router = express.Router();
var fs = require('fs');
var images = fs.readFileSync('./images/ab.png').toString('base64');

//人脸识别接口
var token = "24.b4dc88ca85d9a5c59b76e659a3f5584e.2592000.1666428195.282335-27584508";

//url  林更新
// var str = './images/ab.png'

router.post('/fa', (req, res) => {
	let options = {
		host: 'aip.baidubce.com',
		path: '/rest/2.0/face/v3/search?access_token="' + token + '"',
		method: 'POST',
		headers: {
			'Content-Type': 'application/json',
		}
	};

	let contents = JSON.stringify({
		// url  图片类型
		image: images,
		image_type: "BASE64",
		group_id_list: "test"
		//这里根据文档填入你想要获取到的参数
	});

	let req_baiduai = https.request(options, function(res_baiduai) {
		res_baiduai.setEncoding('utf8');
		res_baiduai.on('data', function(chunk) {
			res.send(chunk)
			// var testResult = JSON.parse(chunk);
			console.log('chunk', chunk)
			res.end();
		})
	});
	req_baiduai.write(contents);
	req_baiduai.end();
});
module.exports = router;

// {
// 	"error_code": 0,
// 	"error_msg": "SUCCESS",
// 	"log_id": 1462597306,
// 	"timestamp": 1663838662,
// 	"cached": 0,
// 	"result": {
// 		"face_num": 1,
// 		"face_list": [{
// 			"face_token": "97e7e44f62c4526447a9bb442e2c6499",
// 			"location": {
// 				"left": 157.09,
// 				"top": 148.92,
// 				"width": 75,
// 				"height": 80,
// 				"rotation": -3
// 			},
// 			"face_probability": 1,
// 			"angle": {
// 				"yaw": 3.64,
// 				"pitch": -3.2,
// 				"roll": -7.18
// 			},
// 			"age": 21,
// 			"beauty": 58.69
// 		}]
// 	}
// }
